package org.algorithm.wE1.数组.三月.第四周;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author zhx
 * @date 2022-03-21 星期一18:26
 *
 * url: https://leetcode-cn.com/problems/pascals-triangle-ii/
 */
public class 杨辉三角II {

    public static void main(String[] args) {
        System.out.println(getRow(3));
    }


    /**
     * 输入: rowIndex = 3
     * 输出: [1,3,3,1]
     *
     * 输入: rowIndex = 0
     * 输出: [1]
     *
     *
     * 输入: rowIndex = 1
     * 输出: [1,1]
     */
    public static List<Integer> getRow(int numRows) {
        if(numRows == 0){
            return Arrays.asList(1);
        }
        List<Integer> pre = new ArrayList<>();
        for (int i = 0; i <numRows ; i++) {
            List<Integer> row = new ArrayList<>();
            for (int j = 0; j <=i ; j++) {
                if(j==0 || j==i){
                    row.add(1);
                }else {
                    row.add(pre.get(j-1)+pre.get(j));
                }
            }
            pre = row;
        }
        return pre;
    }
}
